<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Purchase;
use App\Models\Purchase_type;

class PurchaseController extends Controller
{
    public function index(Request $request)
    {
        $id = $request->query('id', 1);
        $purchase_type = Purchase_type::where('id', $id)->first();
        $purchases = $purchase_type->purchases()->take(10)->get();
        return view('purchase.pc.index', compact('purchases', 'purchase_type'));
    }

    public function show($id)
    {
        $purchase = Purchase::where('id', $id)->first();
        return view('purchase.pc.show', compact('purchase'));
    }

    public function wap_index()
    {
        return redirect(route('purchase.wap_type', 1));
    }

    public function wap_type($id)
    {
        $types = Purchase_type::take(3)->get();
        $purchases = Purchase_type::where('id', $id)->first()->purchases()->take(10)->get();
        return view('purchase.mobile.type', compact('types','purchases'));
    }

    public function wap_show($id)
    {
        $purchase = Purchase::where('id', $id)->first();
        return view('purchase.mobile.show', compact('purchase'));
    }
}
